# -*- coding:utf-8 -*-

import configparser, importlib, sys
from os import path
importlib.reload(sys)

# 返回当前文件所在的目录
d = path.dirname(__file__)
# 获得d所在的目录，既d的父级目录
parent_path = path.dirname(d)
cf = "config.ini"

proDir = path.join(parent_path, "config")
configPath = path.join(proDir, cf)


class ReadConfig():
    def __init__(self):
        self.cf = configparser.ConfigParser()
        # self.configPath = config()
        self.cf.read(configPath, encoding='utf-8')

    def get_env(self, name):
        value = self.cf.get("env", name)
        return value

    def set_env(self, name):
        self.cf.set("env", "env", name)

        try:
            with open(configPath, "w+") as f:
                self.cf.write(f)
        except Exception as e:
            pass


    def get_case(self, name):
        value = self.cf.get("case", name)
        return value

    def set_case(self, name):
        self.cf.set("case", "case", name)

        try:
            with open(configPath, "w+") as f:
                self.cf.write(f)
        except Exception as e:
            pass